<template>
  <div class="passenger">
    <a-card title="座位管理">
      <a-form layout="inline" :model="formObj">
        <a-form-item>
          <TrainSelect v-model:code="formObj.trainCode" width="200px" />
        </a-form-item>
        <a-form-item>
          <a-button type="primary" @click="getList">查询</a-button>
        </a-form-item>
        <a-form-item>
          <a-button @click="reset">重置</a-button>
        </a-form-item>
      </a-form>
    </a-card>
    <a-table :data-source="dataList" :columns="columns" :pagination="false"></a-table>
    <a-pagination
      v-model:current="formObj.page"
      v-model:page-size="formObj.pageSize"
      align="right"
      :total="formObj.total"
      show-size-changer
      style="margin-top: 20px"
      @change="onChange"
    />
  </div>
</template>
<script setup lang="ts">
import { onMounted, ref } from 'vue';
import { SeatApi } from '../../api/seat';
import TrainSelect from '@/components/Train-Select.vue';

const columns = ref([
  {
    title: '车次编号',
    dataIndex: 'trainCode',
    key: 'trainCode',
  },
  {
    title: '厢序',
    dataIndex: 'carriageIndex',
    key: 'carriageIndex',
  },
  {
    title: '排号',
    dataIndex: 'row',
    key: 'row',
  },
  {
    title: '列号',
    dataIndex: 'col',
    key: 'col',
  },
  {
    title: '座位类型',
    dataIndex: 'seatTypeName',
    key: 'seatTypeName',
  },
  {
    title: '同车厢座序',
    dataIndex: 'carriageSeatIndex',
    key: 'carriageSeatIndex',
  },
]);
const formObj = ref({
  trainCode: '',
  page: 1,
  pageSize: 10,
  total: 0,
});
onMounted(() => {
  getList();
});
const dataList = ref([]);

const getList = async (): Promise<void> => {
  const { data } = await SeatApi.query(formObj.value);
  dataList.value = data.records || [];
  formObj.value.total = data.total;
};
const reset = (): void => {
  formObj.value.trainCode = '';
  getList();
};
const onChange = (current: number, pageSize: number): void => {
  console.log(current, pageSize);
  formObj.value.page = current;
  formObj.value.pageSize = pageSize;
  getList();
};
</script>

<style scoped lang="less">
.passenger {
  :global(.ant-modal .ant-modal-footer) {
    text-align: center;
  }
}
</style>
